package cn.imnaer.rest.controller;

import java.util.List;

import javax.jws.WebService;

import cn.imnaer.service.rest.collect.CollectComponentRestApi;
import cn.imnaer.service.rest.resquest.model.CollectParams;
import cn.imnaer.service.rest.view.model.CollectGroupView;
import cn.imnaer.service.rest.view.model.RecommendView;
import cn.imnaer.service.rest.view.model.SimpleResponse;
import cn.imnaer.service.rpc.collect.CollectComponentRpcApi;
import cn.imnaer.service.rpc.collect.application.CollectComponentRpcApiImpl;

@WebService
public class CollectComponentController implements CollectComponentRestApi {
	public CollectComponentRpcApi collectComponentRpcApi;
	private SimpleResponse response = new SimpleResponse();
	public CollectComponentController() {
		collectComponentRpcApi = new CollectComponentRpcApiImpl();
	}

	@Override
	public String collect(String collectParamsJson) {
		CollectParams collectParams = CollectParams.parseToModel(collectParamsJson);
		if (collectParams != null) {
	        RecommendView view = collectComponentRpcApi.createCollect(collectParams);
			return this.response.success(view);
		}
		return this.response.jsonException();
	}

	@Override
	public String deleteCollect(String collectsParamsJson) {
		CollectParams collectParams = CollectParams.parseToModel(collectsParamsJson);
		if (collectParams != null) {
				collectComponentRpcApi.deleteCollect(collectParams);
				return this.response.success();
	}
	return this.response.jsonException();
	}

	public String getCollectGroupList(String userId) {
		List<CollectGroupView> record = collectComponentRpcApi.getCollectGroupList(userId);
		return this.response.success(record);
		

	}
	@Override
	public String getCollectItemList(String collectId) {
		List<RecommendView> record = collectComponentRpcApi.getCollectGroupItemList(collectId);
		return this.response.success(record);
	}



	@Override
	public String createGroup(String userId, String groupName) {
		
	CollectGroupView collectGroupView = this.collectComponentRpcApi.createCollectGroup(userId, groupName);
		return this.response.success(collectGroupView);
	}



}
